home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / ask_hot.cpp < prev    next >
C/C++ Source or Header  |  1994-10-10  |  3KB  |  114 lines

  1. #include "ask_hot.h"
  2. #include "blkmenu.h"
  3. #include "button.h"
  4.  
  5. enum { SAVE = 1, DONT_SAVE };
  6.  
  7. int ask_save()
  8.     {
  9.     rect base;
  10.     base = rect(20, 10, 50, 15);
  11.     char* menuList[] = { "    Yes    ", "   No    ", "" };
  12.     TextMenu* menu = new TextMenu(base, "ask_save.pcy",
  13.            " Save the file? Y/N", "YN", 1, 1,
  14.            menuList, rect(0, 24, 79, 25), 0, NULL,
  15.            NULL, FIXED, 6, SHOW_BORDER, SHOW_BORDER, 0, 16);
  16.  
  17.     menu->set_pos(2);
  18.     menu->show_window();
  19.     menu->exe();
  20.     menu->hide();
  21.  
  22.     delete menu;
  23.  
  24.     if(global_num == SAVE)    // YES
  25.     return 1;
  26.     return 0;
  27.     }
  28. //////////////////////
  29. int ask_exit()
  30.     {
  31.     rect base;
  32.     base = rect(20, 10, 50, 15);
  33.  
  34.     char* menuList[] = { "    Yes   ", "    No    ", "" };
  35.     TextMenu* ask_menu = new TextMenu(base, "ask_exit.pcy",
  36.            "Exit program? Y / N ", "YN", 1, 1,
  37.            menuList, rect(0, 24, 79, 25), 0, NULL,
  38.            NULL, FIXED, 6, SHOW_BORDER, SHOW_BORDER, 0, 16);
  39.     ask_menu->show_window();
  40.     ask_menu->exe();
  41.     ask_menu->hide();
  42.     if(global_num == 1)    // YES
  43.     {
  44.     delete ask_menu;
  45.     return 1;          // exit
  46.     }
  47.  
  48.     delete ask_menu;
  49.     return 0;
  50.     }
  51. //////////////////////////
  52. int ask_hot_key()    // shows the window with message and gets a key
  53.     {                // for macros. Mouse or ESC are processed as CANCEL-type
  54.     int a;           // event, visible characters are ignored
  55.  
  56.     Window* w = new Window(rect(29, 9, 46, 16),    "hotkey.pcx");
  57.     Button* button = new Button(rect(30, 10, 45, 15),
  58.     "Press hot key\nCTRL\nor ALT", NO_BORDER);
  59.  
  60.     w->show_window();           // window - the "dummy" way to hide button
  61.     button->show();      // button
  62.  
  63.     while(1)
  64.     {
  65.     e = getevent(KEYEVENT | MOUSEEVENT);
  66.     if((e.what = KEYEVENT && e.key == EVENT_ESC) // not possible
  67.         || e.what == MOUSEEVENT)                 // hot key
  68.         {
  69.         a = 0;                // if CANCEL-type event
  70.         break;
  71.         }
  72.     if(!(e.is_char()))
  73.         {
  74.         a = 1;                // if char is visible
  75.         break;
  76.         }
  77.     }
  78.     w->hide();
  79.     delete button;
  80.     delete w;
  81.     return a;   // a == 0 if CANCEL and a == 1 if hot key inserted
  82.     }
  83. /////////////////////////
  84. void add_macros(char* command, FILE* tempPtr)  // add macros to macros file
  85.     {
  86.     char header[22];                       // new macros header
  87.     header[0] = '$';                       // leadind '$'
  88.     strcpy(header + 1, command);           // "$ <hot key> "
  89.     header[strlen(command) + 1] = '\n';
  90.     header[strlen(command) + 2] = '\0';    // "$ <hot key> \n\0"
  91.  
  92.     fputs(header, tempPtr);                // write it to file as the first line
  93.  
  94.     char str[82];
  95.     while(fgets(str, 80, scriptPtr) > 0)   // copy all script to macros file
  96.     {
  97.     fputs(str, tempPtr);
  98.     }
  99.     fputc('\n', tempPtr);                  // not absolutely necessary
  100.  
  101.     while(fgets(str, 80, macrosPtr) > 0)   // copies last macroses from
  102.     {                                  // macros file
  103.     char* i;
  104.     if(str[0] == '$' && !strncmp(str, header, strlen(str) - 2))          // if this macros is already defined
  105.         {
  106.         while((i = fgets(str, 80, macrosPtr))[0] != '$' // str = "$ <ALT_F1>\n"
  107.         && i)                                       // header = "$ ALT_F1> '\n"
  108.         ;                             // skip macros which is replaced
  109.         }
  110.     fputs(str, tempPtr);
  111.     }
  112.  
  113.     }
  114. /////////////////////////